<?php
include '../config/db_config.php';
include '../lib/kelola_produk.php';
include '../lib/kelola_gambar.php';
session_start();
//var_dump($_SESSION);
//echo count($_SESSION);
if(!isset($_SESSION)){
	header('location:login.php');
	//var_dump($_SESSION);
}

$kelola_produk = new kelola_produk();
$kelola_gambar = new kelola_gambar();



$result = $kelola_produk->select_produk_by_technopreneur($_SESSION['ID_TECHNOPRENEUR']);

//$search;
//while ($row = mysql_fetch_assoc($result)) {
	//$search = $row;
	//var_dump($result);
//}
$produk;
while ($row = mysql_fetch_assoc($result)) {
	$p = array();
	
	$p['ID_PRODUK'] = $row['ID_PRODUK'];
	$p['NAMA_PRODUK'] = $row['NAMA_PRODUK'];
	$p['HARGA'] = $row['HARGA'];
	$p['DESKRIPSI_PRODUK'] = $row['DESKRIPSI_PRODUK'];
	
	$result2 = $kelola_gambar->select_gambar($p['ID_PRODUK'], 1);
	while ($row2 = mysql_fetch_assoc($result2)) {
		$p['URL']= $row2['URL']; 
			
}
$produk[]=$p;
//var_dump($p);
}
//var_dump($produk);
?>

<html>
  <head>
    <title>Smart Commerce</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet">
	<style type="text/css">
      body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
    </style>
    <link href="../css/bootstrap-responsive.min.css" rel="stylesheet">
	<script src="../js/jquery-1.7.2.min.js"></script>
	<script src="../js/bootstrap.min.js"></script>
</head>
<body>
	<div class="navbar navbar-inverse navbar-fixed-top">
		<div class="navbar-inner">
			<div class="container">
			<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
			</a>
			
			<a class="brand" href="home_technopreneur.php">Beranda</a>
			<a class="brand">Tentang Kami</a>
			<a class="brand">Kontak</a>
			
				<div class="nav-collapse collapse">
				<form class="navbar-form pull-right" method="post">
				</form>
			<div class="navbar-form pull-right">
				<a href="profil_technopreneur.php" class="btn btn-small btn-primary">Profil</a>
				<a href="../logout.php" class="btn btn-small btn-primary">Logout</a>
			</div>
				
			    </div>
			</div>
		</div>
    </div>
	
	<div class="container">
		<div class="hero-unit"style="background-image:url('../images/header.jpg');" >
			<h1>Smart Commerce</h1>
			<blockquote class="pull-right"> 
				<p>Website khusus Technopreneur Surabaya</p>
			</blockquote>
		</div>
			
		<ul class="breadcrumb">
			<li><a href="home_technopreneur.php">Home</a> <span class="divider">/</span></li>
			<li class="active">Profil</li>
		</ul>
		<div class="container">
		<h3>Daftar Produk Technopreneur</h3>
		<table class='table table-bordered table-hover' style='width:850;' border='0' cellspacing='0' cellpadding='2'>
		<?php
		if (@$produk > 0){
		for ($i=0 ; $i<count($produk); $i++){
			echo '<tr>';
			echo '<td>';
			//echo '<div class="row">';
			 echo '<a href="informasi_produk.php?id='.$produk[$i]['ID_PRODUK'].'" class="pull-left">';
			echo '<div class="span2">';
				if (isset($produk[$i]['URL'])){
				echo '<img class="span2" src="../'.$produk[$i]['URL'].'" style="width:250px; heigth:150px;">';}
				else {
				echo '<img class="span2" src="../images/no_image.jpg" style="width:250px; heigth:150px;">';}
			  echo '</div>';
			  echo '<div class="span1"></div>';
			  echo '<div class="span7" style="vertical-align:top; color:black; ">';
				echo '<h4>'.$produk[$i]['NAMA_PRODUK'].'('.$produk[$i]['HARGA'].')</h4>';
				echo ''.$produk[$i]['DESKRIPSI_PRODUK'].'';
			  echo '</div>';
			   echo '</a>';
			  echo '<div class="span1"></div>';
			  echo '<div class="span1" style="vertical-align:middle; align:right; color:black" >';
				echo '<a class="btn btn-primary" href="edit_produk.php?id='.$produk[$i]['ID_PRODUK'].'">Edit</a> ';
				echo '<br><br>';
				echo '<button class="btn btn-danger" href="hapus_produk.php" onclick="hapus(\''.$produk[$i]['ID_PRODUK'].'\')">Hapus</button> ';
			  echo '</div>';
			 
			 // echo '</div>';
			echo '</td>';
			echo '</tr>';
			}
			}
			else {
			echo '<h4>Produk tidak dapat ditemukan</h4>';}
		?>
		</div>
<script>
function hapus(id){
var c=confirm('Anda akan menghapus produk ini. Lanjutkan?');
if(c){
window.location='../hapus_produk.php?id='+id;
}
}
</script>
</body>
</html>